package cn.edu.sie.learnspringboot.controller;

import cn.edu.sie.learnspringboot.domain.Book;
import cn.edu.sie.learnspringboot.service.IBookService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
// 废弃
//@RestController
@RequestMapping("/books")
public class BookControllerOld {
    @Autowired
    private IBookService iBookService;

    @GetMapping
    public List<Book> getAll(){
        return iBookService.list();
    }

    @PostMapping
    public Boolean save(@RequestBody Book book) {
        return iBookService.save(book);
    }

    @PutMapping
    public Boolean update(@RequestBody Book book) {
        return iBookService.updateById(book);
    }

    @DeleteMapping("{id}")
    public Boolean delete(@PathVariable Integer id) {
        return iBookService.removeById(id);
    }

    @GetMapping("{id}")
    public Book selectGetById(@PathVariable Integer id) {
        return iBookService.getById(id);
    }

    @GetMapping("{c}/{s}")
    public IPage<Book> getPage(@PathVariable int c, @PathVariable int s){
        System.out.println("数量 " + c + "长度 " + s);
        return iBookService.getPage(c, s);
    }
}
